package com.gdit.zax.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.gdit.zax.dao.UpLoadDao;
import com.gdit.zax.entitys.Section;
import com.gdit.zax.entitys.UpLoad;
import com.gdit.zax.utils.DBUtil;

public class UpLoadDaoImpl  implements UpLoadDao{
	private PreparedStatement ps;
	private ResultSet rs;
	
	private Connection conn;
	private HttpServletRequest request;
	private HttpServletResponse response;
	
	
	public UpLoadDaoImpl(Connection conn,HttpServletRequest request, HttpServletResponse response) {
		this.conn = conn;
		this.request = request;
		this.response = response;
	}
	
	public boolean addUploda(UpLoad info) {
		try {
			String sql = "insert t_fileupload set Flag=?,FileName=?,FilePath=?";
			ps = conn.prepareStatement(sql);
			ps.setString(1, info.getFlag());
			ps.setString(2, info.getFilename());
			ps.setString(3, info.getFilepath());
			
			int result = ps.executeUpdate();
			if (result!=0) {
				return true;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	public UpLoad getUplodaInfo(String flag) {
		String sql = "select * from t_fileupload where Flag=?";
		try {
			ps = conn.prepareStatement(sql);
			ps.setString(1, flag);
			
			rs = ps.executeQuery();
			
			if(rs.next()){
				UpLoad be = DBUtil.getobject(rs, UpLoad.class);
				return be;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

}
